import {Button, List} from "antd-mobile";
import React, {useEffect, useState} from "react";
import {useLocation, useNavigate} from "react-router-dom";
import {DashboardData, repairInfo} from "../../../Datasource";

const DeviceInfo = () => {
    const location = useLocation()
    const navigate = useNavigate()
    const [item, setItem] = useState<any>({
        name: undefined
    });

    const temp = location.pathname.split('/')
    const typeId = Number(temp[temp.length - 2])
    const deviceId = Number(temp[temp.length - 1])

    useEffect(() => {
        if (location) {
            DashboardData.map((e) => {
                if (e.id === typeId) {
                    e.data.map(a => {
                        if (a.id === deviceId) {
                            setItem(a)
                        }
                    })
                }
            })
        }
    }, [])


    if (item.name) {
        return <div>
            <List mode='card'>
                <List.Item children={'设备名称'} extra={item.name}/>
                <List.Item children={'机房名称'} extra={item.machineRoom}/>
                <List.Item children={'所属区县'} extra={item.district}/>
                <List.Item children={'设备类型'} extra={item.type ? '空调' : '蓄电池'}/>
                {typeId === 1 &&
                    <List.Item children={'送风方式'} extra={item.supplyMode}/>}
                <List.Item children={'额定容量'} extra={item.capacity + 'Ah'}/>
                <List.Item children={'出厂日期'} extra={item.productionTime}/>
                <List.Item children={'修改人'} extra={item.updatePerson}/>
                <List.Item children={'修改时间'} extra={item.updateTime}/>
            </List>
            <div style={{margin: '0 12px'}}>
                <Button block type='submit' color='primary' size='large' onClick={() => {
                    navigate(`/device/edit/${typeId}/${deviceId}`)
                }}>
                    修改
                </Button>
            </div>
        </div>
        // }
    } else {
        return null
    }
}

export default DeviceInfo
